package com.xiaodu.spring.base;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

/**
 * @author: dutianjie
 * @date: 2021/5/4
 * @version: v1.0.0
 * @description: 描述
 **/
@Component
public class SpringBeanUtil implements ApplicationContextAware {


     static ApplicationContext applicationContext;


    public static Object getBean(String beanName) {
        return applicationContext.getBean(beanName);
    }

    public static <T>T getBean(Class<T> tClass) {
        return applicationContext.getBean(tClass);
    }


    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        SpringBeanUtil.applicationContext = applicationContext;
    }
}
